<!--
 * @Author: lwHao
 * @Date: 2020-09-17 17:37:58
 * @LastEditors: lwHao
 * @LastEditTime: 2020-09-20 16:33:22
-->
<template>
  <div class="article-page">
    <div class="banner">
      <div class="container">
        <h1>{{ article.title }}</h1>
        <articleMeta :article="article"></articleMeta>
      </div>
    </div>

    <div class="container page">
      <div class="row article-content">
        <div class="col-md-12" v-html="article.body">
        </div>
      </div>

      <hr />

      <div class="article-actions">
        
        <articleMeta :article="article" authorColor="#5cb85c"></articleMeta>
      </div>
      <articleComments :article="article" ></articleComments>
    </div>
  </div>
</template>

<script>
import { getArticle } from '@/api/article'
import markdownIt from 'markdown-it'
import articleMeta from './components/article-meta'
import articleComments from './components/article-comments'
export default {
  name: 'ArticleIndex',
  components: {articleMeta, articleComments},
  async asyncData({params}) {
    const { data } = await getArticle(params.slug)
    const { article } = data
    const md = new markdownIt()
    article.body = md.render(article.body)
    return {
      article
    }
  },
  head () {
    return {
      title: `${this.article.title} - RealWorld`,
      meta: [
        {
          hid: 'description',
          name: 'description',
          content: this.article.description
        }
      ]
    }
  }

}
</script>

<style>
</style>